﻿using System.ComponentModel;
using RaytracerLib;
using RaytracerLib.RenderableObjects;
using RaytracerLib.Materials;
using RaytracerLib.UVMappers;

namespace Raytracer.PropertyGridDecorators
{
    public class RenderableObjectProperties : OrientedElementProperties
    {
        private RenderableObject m_rederable_object;

        public RenderableObjectProperties(RenderableObject a_rederable_object) :
            base(a_rederable_object)
        {
            m_rederable_object = a_rederable_object;
        }

        [TypeConverter(typeof(MaterialConverter))]
        [Category(Categories.PROPERTIES)]
        public Material Material
        {
            get
            {
                return m_rederable_object.DefaultMaterial;
            }
            set
            {
                if (value == null)
                    return;

                m_rederable_object.DefaultMaterial = value;
            }
        }

        [Category(Categories.PROPERTIES)]
        public bool OneSide
        {
            get
            {
                return m_rederable_object.OneSide;
            }
            set
            {
                m_rederable_object.OneSide = value;
            }
        }

        [Category(Categories.PROPERTIES)]
        public bool Closed
        {
            get
            {
                return m_rederable_object.Closed;
            }
            set
            {
                m_rederable_object.Closed = value;
            }
        }

        [Category(Categories.PROPERTIES)]
        [DisplayName("UV mapping method")]
        public UVMappingMethod UVMappingMethod
        {
            get
            {
                return m_rederable_object.UVMapper.Method;
            }
            set
            {
                m_rederable_object.UVMapper = RaytracerLib.UVMappers.UVMapper.Create(value);

            }
        }

        [Category(Categories.PROPERTIES)]
        [DisplayName("UV mapper")]
        [TypeConverter(typeof(UVMapperConverter))]
        public UVMapperProperties UVMapper
        {
            get
            {
                if (m_rederable_object.UVMapper.Method == UVMappingMethod.Conical)
                    return new UVConicalMapperProperties(m_rederable_object.UVMapper as ConicalUVMapper);
                else if (m_rederable_object.UVMapper.Method == UVMappingMethod.Toroidal)
                    return new UVToroidalMapperProperties(m_rederable_object.UVMapper as TorodidalUVMapper);
                else
                    return null;
            }
        }
    }
}